import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'

Vue.use(VueRouter)

let originPush = VueRouter.prototype.push
VueRouter.prototype.push = function (location, req, res) {
  if (req === 'undefined' || res === 'undefined') {
    return originPush.call(this, location).catch(() => {})
  } else {
    return originPush.call(this, location, req, res)
  }
}
let originReplace = VueRouter.prototype.push
VueRouter.prototype.replace = function (location, req, res) {
  if (req === 'undefined' || res === 'undefined') {
    return originReplace.call(this, location).catch(() => {})
  } else {
    return originReplace.call(this, location, req, res)
  }
}

export default new VueRouter({
  routes,
  scrollBehavior() {
    return { y: 0 }
  },
})
